home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / VB98 / TEMPLATE / PROJECTS / ADDIN.DSR (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-06-18  |  4.5 KB  |  118 lines

  1. VERSION 5.00
  2. Begin {AC0714F6-3D04-11D1-AE7D-00A0C90F26F4} Connect 
  3.    ClientHeight    =   9945
  4.    ClientLeft      =   1740
  5.    ClientTop       =   1545
  6.    ClientWidth     =   6585
  7.    _ExtentX        =   11615
  8.    _ExtentY        =   17542
  9.    _Version        =   393216
  10.    Description     =   "Add-In Project Template"
  11.    DisplayName     =   "My Add-In"
  12.    AppName         =   "Visual Basic"
  13.    AppVer          =   "Visual Basic 98 (ver 6.0)"
  14.    LoadName        =   "Command Line / Startup"
  15.    LoadBehavior    =   5
  16.    RegLocation     =   "HKEY_CURRENT_USER\Software\Microsoft\Visual Basic\6.0"
  17.    CmdLineSupport  =   -1  'True
  18. Attribute VB_Name = "Connect"
  19. Attribute VB_GlobalNameSpace = False
  20. Attribute VB_Creatable = True
  21. Attribute VB_PredeclaredId = False
  22. Attribute VB_Exposed = True
  23. Option Explicit
  24. Public FormDisplayed          As Boolean
  25. Public VBInstance             As VBIDE.VBE
  26. Dim mcbMenuCommandBar         As Office.CommandBarControl
  27. Dim mfrmAddIn                 As New frmAddIn
  28. Public WithEvents MenuHandler As CommandBarEvents          'command bar event handler
  29. Attribute MenuHandler.VB_VarHelpID = -1
  30. Sub Hide()
  31.     On Error Resume Next
  32.     FormDisplayed = False
  33.     mfrmAddIn.Hide
  34. End Sub
  35. Sub Show()
  36.     On Error Resume Next
  37.     If mfrmAddIn Is Nothing Then
  38.         Set mfrmAddIn = New frmAddIn
  39.     End If
  40.     Set mfrmAddIn.VBInstance = VBInstance
  41.     Set mfrmAddIn.Connect = Me
  42.     FormDisplayed = True
  43.     mfrmAddIn.Show
  44. End Sub
  45. '------------------------------------------------------
  46. 'this method adds the Add-In to VB
  47. '------------------------------------------------------
  48. Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
  49.     On Error GoTo error_handler
  50.     'save the vb instance
  51.     Set VBInstance = Application
  52.     'this is a good place to set a breakpoint and
  53.     'test various addin objects, properties and methods
  54.     Debug.Print VBInstance.FullName
  55.     If ConnectMode = ext_cm_External Then
  56.         'Used by the wizard toolbar to start this wizard
  57.         Me.Show
  58.     Else
  59.         Set mcbMenuCommandBar = AddToAddInCommandBar("My AddIn")
  60.         'sink the event
  61.         Set Me.MenuHandler = VBInstance.Events.CommandBarEvents(mcbMenuCommandBar)
  62.     End If
  63.     If ConnectMode = ext_cm_AfterStartup Then
  64.         If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
  65.             'set this to display the form on connect
  66.             Me.Show
  67.         End If
  68.     End If
  69.     Exit Sub
  70. error_handler:
  71.     MsgBox Err.Description
  72. End Sub
  73. '------------------------------------------------------
  74. 'this method removes the Add-In from VB
  75. '------------------------------------------------------
  76. Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
  77.     On Error Resume Next
  78.     'delete the command bar entry
  79.     mcbMenuCommandBar.Delete
  80.     'shut down the Add-In
  81.     If FormDisplayed Then
  82.         SaveSetting App.Title, "Settings", "DisplayOnConnect", "1"
  83.         FormDisplayed = False
  84.     Else
  85.         SaveSetting App.Title, "Settings", "DisplayOnConnect", "0"
  86.     End If
  87.     Unload mfrmAddIn
  88.     Set mfrmAddIn = Nothing
  89. End Sub
  90. Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
  91.     If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
  92.         'set this to display the form on connect
  93.         Me.Show
  94.     End If
  95. End Sub
  96. 'this event fires when the menu is clicked in the IDE
  97. Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  98.     Me.Show
  99. End Sub
  100. Function AddToAddInCommandBar(sCaption As String) As Office.CommandBarControl
  101.     Dim cbMenuCommandBar As Office.CommandBarControl  'command bar object
  102.     Dim cbMenu As Object
  103.     On Error GoTo AddToAddInCommandBarErr
  104.     'see if we can find the Add-Ins menu
  105.     Set cbMenu = VBInstance.CommandBars("Add-Ins")
  106.     If cbMenu Is Nothing Then
  107.         'not available so we fail
  108.         Exit Function
  109.     End If
  110.     'add it to the command bar
  111.     Set cbMenuCommandBar = cbMenu.Controls.Add(1)
  112.     'set the caption
  113.     cbMenuCommandBar.Caption = sCaption
  114.     Set AddToAddInCommandBar = cbMenuCommandBar
  115.     Exit Function
  116. AddToAddInCommandBarErr:
  117. End Function
  118.